package it.polimi.swKnights.SWIMv2.servlets.search;

import it.polimi.swKnights.SWIMv2.general.WebsiteParameters;
import it.polimi.swKnights.SWIMv2.servlets.SwimServlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class NormalSearchController
 */
public class NormalSearchController extends SwimServlet
{
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{

		Object o = request.getAttribute("userResultMap");// /list --> map
		List<Map<String, String>> listMapResults;

		if (o != null)
		{
			listMapResults = this.getList(o);
			request.setAttribute("userResultList", listMapResults);
		}

		String query = (String) request.getAttribute("query");

		String destination;
		destination = WebsiteParameters.normalSearchFormUrl;

		if (query != null)
		{
			destination = destination.concat("?query=" + query);
		}
		else
		{
			destination = destination.concat("?status=begin");
		}

		request.getRequestDispatcher(destination).forward(request, response);
	}

}
